package com.wh.custom.controller;

import com.wh.custom.service.ICustomReturnVisitService;
import com.wh.custom.pojo.CustomReturnVisit;
import com.wh.custom.dto.CustomReturnVisitDto;
import com.wh.basic.vo.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
* 后端接口类；
*/
@RestController
@RequestMapping("/customReturnVisit")
public class CustomReturnVisitController {

    @Autowired
    public ICustomReturnVisitService customReturnVisitService;

    /**
     * 接口：添加或修改
     * @param customReturnVisit 传递的实体
     * @return AjaxResult 响应给前端
     */
    @PutMapping
    public AjaxResult addOrUpdate(@RequestBody CustomReturnVisit customReturnVisit) {
        if ( customReturnVisit.getId() != null){
            customReturnVisitService.updateById(customReturnVisit);
        }else{
            customReturnVisitService.add(customReturnVisit);
        }
        return new AjaxResult();

    }
   @PutMapping("/follow")
   public AjaxResult addFollow(@RequestBody  CustomReturnVisit customReturnVisit){
        customReturnVisitService.addFollow(customReturnVisit);
        return new AjaxResult();

   }
    /**
    * 接口：删除
    * @param id
    * @return AjaxResult 响应给前端
    */
    @DeleteMapping(value = "/{id}")
    public AjaxResult del(@PathVariable("id") Long id) {
        customReturnVisitService.deleteById(id);
        return new AjaxResult();
    }

    /**
    * 接口：批量删除
    * @param ids
    * @return AjaxResult 响应给前端
    */
    @PatchMapping
    public AjaxResult patchDel(@RequestBody List<Long> ids) {
        customReturnVisitService.patchDel(ids);
        return new AjaxResult();
    }

    /**
    * 接口：查询客户的所有回访记录
    * @param customerId
    */
    @GetMapping("/{customId}")
    public List<CustomReturnVisit> customerAllFollowUp(@PathVariable("customId")  Integer customerId) {
        return customReturnVisitService.customerAllFollowUp(customerId);
    }


    /**
    * 接口：查询所有
    * @return
    */
    @GetMapping
    public List<CustomReturnVisit> findAll() {
        return customReturnVisitService.findAll();
    }


    /**
     * 接口：分页查询或高级查询
     * @param customReturnVisitDto 查询对象
     * @return IPage<CustomReturnVisit> 分页对象
     */
    @PostMapping
    public IPage<CustomReturnVisit> findByPage(@RequestBody CustomReturnVisitDto customReturnVisitDto) {
        return customReturnVisitService.findByPage(customReturnVisitDto);
    }
}
